package dev.blogmoon.cn.admin.controller;

import dev.blogmoon.cn.common.entity.BatchRemoveReq;
import dev.blogmoon.cn.common.entity.PageResult;
import dev.blogmoon.cn.common.entity.Result;
import dev.blogmoon.cn.system.module.QueryDictReq;
import dev.blogmoon.cn.system.module.SysDictDTO;
import dev.blogmoon.cn.system.module.SysDictValueDTO;
import dev.blogmoon.cn.system.repository.SysDictRepository;
import dev.blogmoon.cn.system.repository.SysDictValueRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/admin/dict-value")
public class SysDictValueController {

    @Autowired
    private SysDictValueRepository sysDictValueRepository;

    @PostMapping("/page")
    public Result page(@RequestBody QueryDictReq req) {
        PageResult<SysDictValueDTO> pageResult = sysDictValueRepository.page(req);
        return Result.success(pageResult);
    }

    @PostMapping("/save")
    public Result save(@RequestBody SysDictValueDTO sysDictValueDTO) {
        sysDictValueRepository.save(sysDictValueDTO);
        return Result.success();
    }

    @GetMapping("/detail")
    public Result detail(@RequestParam("id")Long id){
        SysDictValueDTO sysDictDTO = sysDictValueRepository.getById(id);
        return Result.success(sysDictDTO);
    }

    @PostMapping("/delete")
    public Result removeById(@RequestBody BatchRemoveReq req){
        sysDictValueRepository.remove(req.getIds());
        return Result.success();
    }

}
